<!-- 分类 -->
<template>
  <div class="mall-class">
    <van-nav-bar fixed title="商品分类" safe-area-inset-top @click-left="() => $router.push({ path: '/' })">
      <template #left>
        <img style="width: 30px" src="../../assets/images/返回首页.png" alt="" />
      </template>
    </van-nav-bar>
    <!-- 内容 -->
    <van-search shape="round" @search="onSearch" v-model="search.searchkey" placeholder="请输入搜索关键词" />
    <!-- 列表 -->
    <div class="content">
      <van-sidebar v-model="activeKey" @change="onChange">
        <van-sidebar-item :title="item.name" v-for="item in list" :key="item.id" />

      </van-sidebar>
      <div class="list">
        <!-- 循环item -->
        <div class="item">
          <div class="title">
            <div>——{{typename}}——</div>
            <!-- <div>更多
              <van-icon name="arrow" />
            </div> -->
          </div>
          <van-grid :column-num="typelist.length" :border="false">
            <van-grid-item @click="goitem(value)" v-for="value in typelist" :key="value.id" :icon="value.imgurl"
              :text="value.name" />
          </van-grid>
        </div>

      </div>
    </div>
  </div>
</template>

<script>

import { category } from "../../api/cate";
export default {
  name: "",
  data() {
    return {
      search: {
        searchkey: ""
      },
      activeKey: "",
      list: [],
      typelist: [],
      typename: ""
    };
  },
  methods: {
    goitem(uitem) {
      this.$router.push({ path: "/goods", query: { typeid: uitem.id } });
    },
    onSearch(val) {

      this.getData();
    },
    onChange(index) {
      console.log("index", index);
      this.showType(index);
    },
    async getData() {
      let res = await category(this.search);
      if (res.status == 200) {
        var data = res.data;
        this.list = data;
        if (data.length > 0) {

          this.showType(0);
        }
      }
    },
    showType(index) {
      console.log(" this.list[index]", this.list[index]);
      this.typename = this.list[index].name;
      this.typelist = this.list[index].data;
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() { },
};
</script>

<style lang="scss" scoped>
.mall-class {
  width: 100%;
  padding-top: 92px;

  .content {
    width: 100%;
    min-height: 77.5vh;
    display: flex;

    .list {
      padding: 30px 0;
      flex: 1;
      background-color: #fff;

      .item {
        .title {
          font-size: 28px;
          margin-left: 30%;
          width: 70%;
          display: flex;
          justify-content: space-between;
          margin-bottom: 20px;

          :last-child {
            color: #ccc;
          }
        }
      }
    }
  }
}
</style>